/**
 * 教师后台js
 * @authors dr2009 (1085388169@qq.com)
 * @date    2014-10-14 14:57:05
 * @version 1.0
 */

$(function() {
    //主菜单
    $("#nav li").click(function() {
        $(this).addClass('actived').siblings().removeClass('actived');
    });
    // 次级菜单
    $(".submenu li").click(function() {
        $(this).addClass('actived').siblings().removeClass('actived');
    });

    // tab菜单
    $(document).on('click', '.tab-menu li', function(event) {
        $(this).addClass('actived').siblings().removeClass('actived');
        var index = $('.tab-menu li').index(this);
        $('.tab-content .tab-item').eq(index).show().siblings().hide();
    });

    // placeholder兼容
    if (!('placeholder' in document.createElement('input'))) {
        $('input[placeholder],textarea[placeholder]').each(function() {
            var that = $(this),
                    text = that.attr('placeholder');
            if (that.val() === "") {
                that.val(text).addClass('placeholder');
            }
            that.focus(function() {
                if (that.val() === text) {
                    that.val("").removeClass('placeholder');
                }
            }).blur(function() {
                if (that.val() === "") {
                    that.val(text).addClass('placeholder');
                }
            })
                    .closest('form').submit(function() {
                if (that.val() === text) {
                    that.val('');
                }
            });
        });
    }
    // 分页跳转（）
    $('.pagination input:submit').click(function() {
        if ($('.pagination input:text').val() === '') {
            alert('页码不能为空');
            return false;
        }
    });
    // 关闭弹窗
    $('#modal').on('click', '.btn-closed , .btn-cancel', function() {
        // $('#modal .btn-closed, #modal .btn-cancel').click(function() {
        $('#modal').hide();
        $('#modal .modal-box').hide();
        $('#modal .modal-overlay').hide();
        $mask.hide();
    });
    // 提交
    $('#modal').on('click', '.btn-yes', function() {
        // $(this).closest('form').submit();
        $mask.hide();
    });

    /*------------------------------
     
     高校基本信息弹窗
     
     ------------------------------*/
    //通用
    $('.btn-modal').on("click", function() {
        showModal();
        $('#modal input:text, #modal textarea').val('');
        $("#modal .input-file img").attr('src', '');
        $("#modal form").attr('action', $('#addUrl').val());
    });
    // $('.btn-editor').on("click", function(){
    // 	// showModal();
    // 	$("#modal form").attr('action',$('#updateUrl').val());
    // });


});//jquery ready结束

/*------------------------------
 
 高校地址
 
 ------------------------------*/
function moduleAddress() {
    var $addrLI = $('.content .addr-dd li');

    // 增加地址(弹窗)
    $('.btn-add-addr').click(function() {
        showModal();
    });

    // 按钮组移入移出
    $addrLI.mouseover(function() {
        if ($(this).find('input:radio').prop('checked')) {
            $(this).find('.btn-addr-main').hide();
        } else {
            $(this).find('.btn-addr-main').show();
        }
        $(this).children('i').show();
    }).mouseout(function() {
        if (!$(this).find('input:radio').prop('checked')) {
            $('#main .btn-addr-main').show();
        }
        $(this).children('i').hide();
    });

    // 选中设为主校区
    $addrLI.find('.btn-addr-main').on("click", function() {
        $addrLI.find('input:radio').prop('checked', false);
        var address_id = $(this).parent().siblings('input:hidden[name=address_id]').val();
        var url = $("#setMainUrl").val();
        $.post(url, {'address_id': address_id},
        function(data) {
        });
        $(this).parent().siblings('input:radio').prop('checked', true);
    });

    // 新增地址
    $('#btn-add-addr').on("click", function() {
        $('#modal_address h2').text('新增校区地址');
        //重置内容
        $('#school_name').val('');
        $('#school_address').val('');
        $('#school_zipcode').val('');
        $('#province').val('0');
        $('#city').val('0');
        $('#county').val('0');
        $('#coordinate_x').val('');
        $('#coordinate_y').val('');
        
        //
        $('#form-add').attr("action", $('#addUrl').val());
        showModal(modal_address);
    });

    // 编辑
    $addrLI.find('.btn-addr-editor').on("click", function() {
        $('#modal_address h2').text('校区地址编辑');
        $('#form-add').attr("action", $('#updateUrl').val());

        var address_id = $(this).parent().siblings('input:hidden[name=address_id]').val();
        $('#address_id').val(address_id);

        // 返回内容
        var name = $(this).parent().siblings('input:hidden[name=name]').val();
        var school_address = $(this).parent().siblings('input:hidden[name=school_address]').val();
        var zip = $(this).parent().siblings('input:hidden[name=zip]').val();
        var province = $(this).parent().siblings('input:hidden[name=province_id]').val();
        var city = $(this).parent().siblings('input:hidden[name=city_id]').val();
        var county = $(this).parent().siblings('input:hidden[name=county_id]').val();
        var coordinate_x = $(this).parent().siblings('input:hidden[name=coordinate_x]').val();
        var coordinate_y = $(this).parent().siblings('input:hidden[name=coordinate_y]').val();

        
        $('#coordinate_x').val(coordinate_x);
        $('#coordinate_y').val(coordinate_y);
        $('#school_name').val(name);
        $('#school_address').val(school_address);
        $('#school_zipcode').val(zip);

        $('#province').val(province);
        change(1);
        $('#city').val(city);
        change(2);
        $('#county').val(county);

        showModal(modal_address);
    });
    // 删除
    $addrLI.find('.btn-addr-remove').on("click", function() {
        var address_id = $(this).parent().siblings('input:hidden[name=address_id]').val();
        var url = $("#deleteUrl").val();
        var $that = $(this);
        $.post(url, {'address_id': address_id},
        function(data) {
            $that.closest('li').remove();
        });
    });
}


/*------------------------------
 
 查看详细评论
 
 ------------------------------*/
function commentQuestion() {
    //查看详细评论
    // 弹窗
    $('.btn-comment ').on('click', function() {
        var comment_id = $(this).parent().children("input[name=comment_id]").val();
        var url = $("#commentselect").val();
        var $this = $(this);
        $.post(url, {
            "comment_id": comment_id
        }, function(data) {
            $("#comment-title").text(data.user_name + ":" + data.title);
            //教学质量
            $("#teaching_int").addClass("star-" + parseInt(data.teaching_int));
            $("#teaching").text(data.teaching);
            //师资力量
            $("#teacher_int").addClass("star-" + parseInt(data.teacher_int));
            $("#teacher").text(data.teacher);
            //设施配套
            $("#facilities_int").addClass("star-" + parseInt(data.facilities_int));
            $("#facilities").text(data.facilities);
            //校园环境
            $("#surrounding_int").addClass("star-" + parseInt(data.surrounding_int));
            $("#surrounding").text(data.surrounding);
            //交通设施
            $("#traffic_int").addClass("star-" + parseInt(data.traffic_int));
            $("#traffic").text(data.traffic);
        });

        showModal();
    });
    // 删除评论

    $('.tab-content').on('click', '.btn-delete', function(event) {
        var comment_id = $(this).parent().children("input[name=comment_id]").val();
        var url = $("#commentsdelete").val();
        var $this = $(this);
        $.post(url, {
            "comment_id": comment_id
        }, function(data) {
            $this.closest('tr').remove();
//                        alert(111)
        }).error(function() {
            alert("error");
        });
    });

}





/*------------------------------
 
 高校详情(不弹窗)
 
 ------------------------------*/
function moduleSchoolIntro() {
    $('#school-detail .btn-editor-2').on("click", function() {
        $(this).hide().siblings('.btn-save').show();
        var $editorTD = $(this).closest('tr').find('td').eq(1);
        var txt = $editorTD.find('p').text();
        var html = '<textarea name="" cols="65" rows="5">' + txt + '</textarea>';
        $editorTD.html(html);
    });
    $('#school-detail .btn-save').on("click", function() {
        $(this).hide().siblings('.btn-editor-2').show();
        var $editorTD = $(this).closest('tr').find('td').eq(1);
        var $editorTD2 = $(this).closest('tr').find('td').eq(2);
        var txt = $editorTD.find('textarea').val();
        var type = $editorTD2.find('input').val();
        var html = '<p>' + txt + '</p>';
        var info_id = $("#info_id").val();
        var url = $("#url").val();
        $.post(url, {'info_id': info_id, 'type': type, 'content': txt},
        function(data) {
        });
        $editorTD.html(html);
    });
}
/*------------------------------
 
 知名校友
 
 ------------------------------*/
function moduleAlumni() {

    var updateUrl = $('#updateUrl').val();
    var deleteUrl = $('#deleteUrl').val();
    var addUrl = $('#addUrl').val();
    var ue = UE.getEditor('alumni_content', {
        initialFrameWidth: 620, //初始化宽度
        initialFrameHeight: 220, //初始化高度
        autoHeightEnabled: false,
        elementPathEnabled: false,
        wordCount: false,
    })
    //新增-修改form地址
    $('.btn-modal').on("click", function() {
        ue.ready(function() {
            ue.setContent("", false); //这里给编辑器添加内容
        });
        $('#form_add').attr('action', addUrl);
    });

    // 编辑
    $('#content-alumni').on('click', '.btn-editor', function() {
        showModal();
        //显示各种信息
        var personImg = $(this).closest('tr').find('td').eq(0).find('img').attr('src');
        var personName = $(this).closest('tr').find('td').eq(0).find('span').text();
        var alumni_id = $(this).closest('tr').find('td').eq(0).find('input').val();
        var personInfo = $(this).closest('tr').find('td').eq(1).find('p').text();
        $("#modal .input-file img").attr('src', personImg);
        $("#modal input:text[name='alumni_name']").val(personName);
        $("#modal input:hidden[name='alumni_id']").val(alumni_id);
//		$("#modal textarea[name='alumni_content']").val(personInfo);
        ue.ready(function() {
            ue.setContent(personInfo, false); //这里给编辑器添加内容
        });

        //修改form地址
        $('#form_add').attr('action', updateUrl);
    });

    // 删除
    $('#content-alumni').on('click', '.btn-remove', function() {
        var alumni_id = $(this).closest('tr').find('td').eq(0).find('input').val();
        var school_id = $("#school_id").val();
        var $that = $(this);

        $.post(deleteUrl, {'alumni_id': alumni_id, 'school_id': school_id},
        function(data) {
            $that.closest('tr').remove();
        });

    });
    // 图片上传预览
    $('#modal_friend input[type = file]').change(function() {
        var objUrl = getObjectURL(this.files[0]);
        // console.log("objUrl = "+objUrl) ;
        if (objUrl) {
            $("#modal .input-file img").attr("src", objUrl);
        }
    });
}
/*------------------------------
 
 院系设置
 
 ------------------------------*/
function moduleDepartments() {
    // 新增弹窗
    $("#modal-department").on("click", function() {

    });
    // 院系列表删除
    $('#content-department .btn-remove').on("click", function() {
        var departments_id = $(this).closest('tr').find('td').eq(2).find('input:hidden').val();
        var school_id = $("#school_id").val();
        var url = $("#deleteUrl").val();
        var $that = $(this);
        $.post(url, {'departments_id': departments_id, 'school_id': school_id},
        function(data) {
            $that.closest('tr').remove();
        });

    });
    // 编辑
    $('#content-department .btn-editor-3').on("click", function() {

        $(this).hide().siblings('.btn-save').show();

        var $editorTitle = $(this).closest('tr').find('td').eq(0);
        var $editorTxt = $(this).closest('tr').find('td').eq(1);
        var title = $editorTitle.text();
        var txt = $editorTxt.find('p').text();
        var title_html = '<input type="text" value=' + title + '>';
        var txt_html = '<textarea name="" cols="65" rows="5">' + txt + '</textarea>';

        $editorTitle.html(title_html);
        $editorTxt.html(txt_html);
    });
    // 保存
    $('#content-department .btn-save').on("click", function() {

        $(this).hide().siblings('.btn-editor-3').show();

        var $editorTitle = $(this).closest('tr').find('td').eq(0);
        var $editorTxt = $(this).closest('tr').find('td').eq(1);
        var title = $editorTitle.find('input').val();
        var txt = $editorTxt.find('textarea').val();
        var school_id = $("#school_id").val();
        var departments_id = $(this).closest('tr').find('td').eq(2).find('input:hidden').val();
        var updateurl = $("#updateUrl").val();
        $.post(updateurl, {
            'school_id': school_id,
            'departments_id': departments_id,
            'departments_name': title,
            'departments_content': txt
        }, function(data) {
            $editorTitle.html(title);
            $editorTxt.html('<p>' + txt + '</p>');
        });
    });

}
/*---------------------------------------------------
 
 文章类页面
 [高校新闻/招生政策/招生计划/招生简章]
 
 ---------------------------------------------------*/
function moduleArticel(site, title, school_id, category_id) {

    //新增tab
    $(document).on("click", "#content-news .btn-tab", function() {

        var newArticleHtml = '<div class="biaoge tab-item actived"><div class="article-box"><form action="' + site + 'addSchoolArticle" method="post"><input type="hidden" name="school_id" value="' + school_id + '"/><input type="hidden" name="category_id" value="' + category_id + '"/><div class="formitm clearfix"><label class="lab">标题：</label><div class="ipt"><input type="text" name="title" class="article-title z-ib" value="" placeholder="填写新闻标题"/></div></div><div class="formitm clearfix"><label class="lab">摘要：</label><div class="ipt"><textarea name="description" class="article-summary"></textarea></div></div><div class="formitm clearfix"><label class="lab">正文：</label><div class="ipt"><textarea name="content" class="article-content" id="article-content"></textarea></div></div><div class="lybtns"><input type="button" value="保存" class="u-btn btn-yes"><button type="button" class="u-btn btn-cancel">取消</button></div></form></div></div>';

        var newArticleTab = '<li class="news actived"><a href="#">' + title + '<span class="tab-close">×</span></a></li>';

        if ($('#content-news .tab-menu li').length == 1) {
            $('#content-news .tab-menu li').removeClass('actived');
            $('#content-news .tab-item').removeClass('actived');
            $('#content-news .tab-menu ul').append(newArticleTab);
            $('#content-news .tab-content').append(newArticleHtml);
        }
        $('#content-news .tab-menu li.actived').trigger('click');
        var ue = UE.getEditor('article-content', {
            initialFrameWidth: 620, //初始化宽度
            initialFrameHeight: 220, //初始化高度
            autoHeightEnabled: false,
            elementPathEnabled: false,
            wordCount: false,
        });
    });

    //删除tab
    $(document).on("click", ".tab-close", function(event) {
        var index = $('.tab-menu li').index($(this).closest('li'));
        $('.tab-item').eq(index).remove();
        // 如果当前tab
        if ($(this).closest('li').hasClass('actived')) {
            $(this).closest('li').prev().trigger('click');
        }
        $(this).closest('li').remove();
        location.reload();//页面重加载
        event.stopPropagation();
    });

    // 编辑文章
    $('#content-news .btn-editor').on('click', function(event) {

        var id = $(this).closest('tr').find('td').eq(2).find('input:hidden').val();
        // $(this).hide();
        $.post(site + 'ajaxArticle', {'id': id}, function(data) {
            // console.log(data);
            var articleTitle = data.title;
            var articleSummary = data.description;
            var articleContent = data.content;
            var editorArticleHtml = '<div class="biaoge tab-item actived"><div class="article-box"><form action="' + site + 'updateSchoolArticle" method="post"><input type="hidden" name="article_id" value="' + data.id + '"/><input type="hidden" name="school_id" value="' + data.school_id + '"/><input type="hidden" name="category_id" value="' + data.category_id + '"/><div class="formitm clearfix"><label class="lab">标题：</label><div class="ipt"><input type="text"  name="title" class="article-title z-ib" value="' + articleTitle + '" placeholder="填写标题"/></div></div><div class="formitm clearfix"><label class="lab">摘要：</label><div class="ipt"><textarea name="description" class="article-summary">' + articleSummary + '</textarea></div></div><div class="formitm clearfix"><label class="lab">正文：</label><div class="ipt"><textarea name="content" class="article-content" id="content-article"></textarea></div></div><div class="lybtns"><input type="button" value="保存" class="u-btn btn-yes"><button type="button" class="u-btn btn-cancel">取消</button></div></form></div></div>';
            var editorArticleTab = '<li class="news actived"><a href="#">' + '编辑' + '<span class="tab-close">×</span></a></li>';
            $('#content-news .tab-menu li').removeClass('actived');
            $('#content-news .tab-item').removeClass('actived');
            $('#content-news .tab-menu ul').append(editorArticleTab);
            $('#content-news .tab-content').append(editorArticleHtml);
            $('#content-news .tab-menu li.actived').trigger('click');

            var ue = UE.getEditor('content-article', {
                initialFrameWidth: 620, //初始化宽度
                initialFrameHeight: 220, //初始化高度
                autoHeightEnabled: false,
                elementPathEnabled: false,
                wordCount: false,
            });
            ue.ready(function() {
                ue.setContent(articleContent, false); //这里给编辑器添加内容
            });

        });
    });

    // 删除文章
    $('#content-news .btn-remove').on('click', function(event) {
        var id = $(this).closest('tr').find('td').eq(2).find('input:hidden').val();
        $.post(site + 'deleteSchoolArticle', {'id': id}, function(data) {
        });
        $(this).closest('tr').remove();
    });

    //tab页面的文章保存
    $(document).on("click", '.btn-yes', function(event) {
        var $this = $(this);
        var url = $(this).closest('form').attr('action');
        var jsondata = $(this).closest('form').serializeObject();
        $.post(url, jsondata, function(data) {
            location.reload();//页面重加载
            $('#content-news .tab-menu li.actived .tab-close').trigger('click');

        });
    });
    // tab页面的文章取消
    $(document).on("click", '.btn-cancel', function(event) {
        $('#content-news .tab-menu li.actived .tab-close').trigger('click');
        
    });


}











/*------------------------------
 
 高校图集
 
 ------------------------------*/
function moduleAblum() {

    var $modalPicture = $('#modal-picture');
    var addImgURL = $('#form-add').attr('action');
    var updateImgURL = addImgURL.slice(0, -6) + 'updateimg';

    //初始化tab位置
    var tabID = $('#tab_type').val();
    $('#content-picture').find('.album-list').hide().eq(tabID - 1).show();
    $('.tab-menu li').eq(tabID - 1).addClass('actived').siblings().removeClass('actived');


    //选项卡.album-list 
    $(document).on('click', '.tab-menu li', function(event) {
        $(this).addClass('actived').siblings().removeClass('actived');
        var index = $('.tab-menu li').index(this);
        $('.tab-content .album-list').eq(index).show().siblings('.album-list').hide();
    });
    // 按钮组消失隐藏
    $('#content-picture .album').on('mouseenter', function() {
        $(this).children('.album-edtior').fadeIn(200);
    }).on('mouseleave', function() {
        $(this).children('.album-edtior').fadeOut(200);
    });

    //上传图片
    $('#btn-upload-img').on('click', function() {
        //显示上传图片按钮
        $('.input-file-box').show();
        //上传类别
        var $activedLI = $('.tab-menu li').find('.actived');
        var imgType = $('.tab-menu li').index($('li.actived')) + 1;
        $modalPicture.find('input[name="img_type"]').val(imgType);
        //修改form地址
        $('#form-add').attr('action', addImgURL);

    });
    // 编辑
    $('#content-picture').on('click', '.btn-rename', function() {
        showModal();
        //隐藏上传图片按钮
        $('.input-file-box').hide();
        // 修改form地址
        $('#form-add').attr('action', updateImgURL);
        //返回当前图片的值，图片地址，描述
        var imgType = $('.tab-menu li').index($('li.actived')) + 1;
        var imgID = $(this).closest('.album').find('input[name="img_id"]').val();
        var imgSrc = $(this).closest('.album').find('img').attr('src');
        var imgAlt = $(this).closest('.album').find('img').attr('alt');
        $modalPicture.find('.descrip textarea').val(imgAlt);
        $modalPicture.find('.img-upload-view img').attr('src', imgSrc);
        $modalPicture.find('.img-upload-view img').attr('alt', imgAlt);
        $modalPicture.find('input[name="img_id"]').val(imgID);
        $modalPicture.find('input[name="img_type"]').val(imgType);
    });
    // 删除
    $('#content-picture .btn-delete').on('click', function() {
        var $form = $(this).closest('.album').find('form');
        $form.submit();
    });
    // 上传
    $('#modal-picture input[type = file]').change(function() {
        var objUrl = getObjectURL(this.files[0]);
        // console.log("objUrl = "+objUrl);
        if (objUrl) {
            $("#modal .img-upload-view img").attr("src", objUrl);
        }
    });
}

/*------------------------------
 
 研招-优秀导师
 
 ------------------------------*/
function moduleTeacher() {

    var updateUrl = $('#updateUrl').val();
    var deleteUrl = $('#deleteUrl').val();
    var addUrl = $('#addUrl').val();

    //新增弹窗（额外）
    $('.btn-modal').on("click", function() {
        // 初始化radio值
        $("#modal input:radio[name = 'teacher-job']").eq(0).prop('checked', true);
        // 修改form地址
        $('#form_add').attr('action', addUrl);
    });

    // 编辑
    $('#content-alumni').on('click', '.btn-editor', function() {
        showModal();
        var personImg = $(this).closest('tr').find('td').eq(0).find('img').attr('src');
        var personName = $(this).closest('tr').find('td').eq(0).find('span').text();
        var alumni_id = $(this).closest('tr').find('td').eq(0).find('input').val();
        var personJob = $(this).closest('tr').find('td').eq(1).text();
        var personInfo = $(this).closest('tr').find('td').eq(2).find('p').text();
        $("#modal .input-file img").attr('src', personImg);
        $("#modal input:text[name='alumni_name']").val(personName);
        $("#modal input:hidden[name='alumni_id']").val(alumni_id);
        $("#modal input:radio[name = 'teacher-job']").each(function(index, ele) {
            if ($(this).val() === personJob) {
                $(this).prop('checked', true);
            }
        });
        $("#modal textarea[name='alumni_content']").val(personInfo);

        //修改form地址
        $('#form_add').attr('action', updateUrl);



    });

    // 删除
    $('#content-alumni').on('click', '.btn-remove', function() {
        var alumni_id = $(this).closest('tr').find('td').eq(0).find('input').val();
        var school_id = $("#school_id").val();
        var $that = $(this);
        $.post(deleteUrl, {'alumni_id': alumni_id, 'school_id': school_id},
        function(data) {
            $that.closest('tr').remove();
        });

    });
    // 图片上传预览
    $('#modal_friend input[type = file]').change(function() {
        var objUrl = getObjectURL(this.files[0]);
        if (objUrl) {
            $("#modal .input-file img").attr("src", objUrl);
        }
    });
}
/*------------------------------
 
 考生问答
 
 ------------------------------*/
function moduleQuestion() {
    var deleteUrl = $('#deleteUrl').val();
    var editorUrl = $('#editorUrl').val();
    // 编辑
    $(document).on('click', ".answer", function(event) {
        showModal();
        var ask_id = $(this).closest('tr').find('td').eq(0).find('input[name=ask_id]').val();
        var title = $(this).closest('tr').find('td').eq(0).find('input[name=title]').val();
        var reply = $(this).closest('tr').find('td').eq(0).find('input[name=reply]').val();

        $('#modal').find('#question-content').text(title);
        $('#modal').find('#ask_id').val(ask_id);
        $('#modal').find('#answer-content').text(reply);

        var $that = $(this);
//	    $.post( editorUrl, { 'ask_id': ask_id },function(data){
//			
//		});

    });
    // 删除
    $('.delete').on('click', function(event) {

        var ask_id = $(this).closest('tr').find('td').eq(0).find('input[name=ask_id]').val();
//            alert(ask_id);
        var $that = $(this);
        $.post(deleteUrl, {'ask_id': ask_id},
        function(data) {
            $that.closest('tr').remove();

        });

    });
}

/*------------------------------
 
 公共函数
 
 ------------------------------*/

// 弹框函数
function showModal() {
    $('#modal').show();
    $('.modal-overlay').show();
    $('#modal').find('.modal-box').show();
    $mask = $(window.top.document).find('#mask');//全局变量
    $mask.show();
    turnCenter();
    return false;
}

// 模态框居中函数
$(window).resize(turnCenter);
function turnCenter() {
    var leftFrameWidth = 190;
    var topFrameHeight = 160;
    $('.modal-box').each(function(index, el) {
        $(el).css({
            position: 'fixed',
            left: ($(window).width() - $(el).outerWidth() - leftFrameWidth) / 2,
            top: ($(window).height() - $(el).outerHeight() - topFrameHeight) / 2
        });
    });
}
//获取图片地址函数
function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL !== undefined) { // basic
        url = window.createObjectURL(file);
    } else if (window.URL !== undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file);
    } else if (window.webkitURL !== undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file);
    }
    return url;
}

// 表单序列化
$.fn.serializeObject = function() {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

	